package com.bauer.base.thread;

public class IssueDemo {

    public static void main(String[] args) {
        Counter counter =  new Counter();
        MyRunable runable =  new MyRunable(counter);
        for (int i=0 ;i<20 ;i++){
            new Thread(runable).start();
        }

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(counter.getI());
    }

    static class MyRunable implements Runnable{

        private int i = 0;

        private Counter counter;

        public MyRunable(Counter counter) {
            this.counter = counter;
        }

        @Override
        public void run() {
//            for(int j= 0;j < 1000 ; j++){
//                i++;
//                try {
//                    Thread.sleep(10);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
            counter.addSafe(1);
//            System.out.println(i);
        }
    }
}
